package org.leviatan.definator.core.admin;

import org.leviatan.common.keyutils.KeyGenerator;
import org.leviatan.definator.core.model.Record;
import org.leviatan.definator.core.model.impl.RecordImpl;

public abstract class RecordHandler {
	
	private static Record activeRecord;
	
	
	
	public static boolean updateRecordName(String recId, String newName) {
		Record rec = RegistryHandler.getRecordModel(recId);
		if (rec != null) {
			rec.setName(newName);
			return true;
		} else 
			return false;
	}
	
	public static boolean updateRecord(Record updateInfo) {
		RecordHandler.activeRecord.setName(updateInfo.getName());
		RecordHandler.activeRecord.setTableRef(updateInfo.getTableRef());
		return true;
	}
	
	public static Record setRecordModel(String recId) {
		Record rec = RegistryHandler.getRecordModel(recId);
		return RecordHandler.setRecordModel(rec);
	}
	
	public static Record setRecordModel(Record aRecord) {
		RecordHandler.activeRecord = aRecord;
		return RecordHandler.activeRecord;
	}
	
	public static Record getActiveRecord() {
		return RecordHandler.activeRecord;
	}
	
	public static Record createNewRecord() {
		Record newRec = new RecordImpl();
		newRec.setId(KeyGenerator.generateUniqueKeyAsString());
		RecordHandler.activeRecord = newRec;
		return newRec;
	}
	
	public static String getRecordId() {
		return RecordHandler.activeRecord.getId();
	}
	
	public static void setRecordName(String aName) {
		RecordHandler.activeRecord.setName(aName);
	}
	
	public static void setRecordTableRef(String aRef) {
		RecordHandler.activeRecord.setTableRef(aRef);
	}
	
	public static String getRecordName() {
		return RecordHandler.activeRecord.getName();
	}
	
	public static String getRecordTableRef() {
		return RecordHandler.activeRecord.getTableRef();
	}

}
